package com.bodu.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.bodu.core.entity.ParamReq;
import com.bodu.system.entity.po.CronTriggersSynchroTimePo;
import com.bodu.system.entity.request.CronTriggersSynchroTimeRequest;
import com.bodu.system.entity.vo.CronTriggersSynchroTimeVo;
import com.bodu.system.mapper.CronTriggersSynchroTimeMapper;
import com.bodu.system.service.CronTriggersSynchroTimeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时任务执行时间 Service impl
 *
 * @author Administrator
 */
@Service
public class CronTriggersSynchroTimeServiceImpl implements CronTriggersSynchroTimeService {

    @Resource
    private CronTriggersSynchroTimeMapper cronTriggersSynchroTimeMapper;

    @Override
    public CronTriggersSynchroTimeVo getModel(Long id) {
        return cronTriggersSynchroTimeMapper.getModel(id);
    }

    @Transactional
    @Override
    public Long save(CronTriggersSynchroTimeRequest request) {
        return cronTriggersSynchroTimeMapper.save(request);
    }

    @Transactional
    @Override
    public Long update(CronTriggersSynchroTimeRequest request) {
        cronTriggersSynchroTimeMapper.update(request);
        return request.getId();
    }

    @Override
    public List<CronTriggersSynchroTimeVo> listPage(ParamReq<CronTriggersSynchroTimeRequest> params) {
        params.setStartIndex((params.getCurrent() - 1) * params.getSize());
        List<CronTriggersSynchroTimeVo> res = cronTriggersSynchroTimeMapper.listPage(params);
        return res;
    }

    @Override
    public Integer countPage(ParamReq<CronTriggersSynchroTimeRequest> params) {
        return cronTriggersSynchroTimeMapper.countPage(params);
    }

    @Override
    public Integer updateDelFlagById(Long id, Integer delFlag) {
        return cronTriggersSynchroTimeMapper.updateDelFlagById(id, delFlag);
    }

    @Override
    public CronTriggersSynchroTimeVo getLastModelByClass(String className) {
        CronTriggersSynchroTimePo cronTriggersSynchroTimePo = cronTriggersSynchroTimeMapper.getLastModelByClass(className);
        if (ObjectUtil.isEmpty(cronTriggersSynchroTimePo)) {
            return null;
        }

        CronTriggersSynchroTimeVo cronTriggersSynchroTimeVo = new CronTriggersSynchroTimeVo();
        BeanUtils.copyProperties(cronTriggersSynchroTimePo, cronTriggersSynchroTimeVo);
        return cronTriggersSynchroTimeVo;
    }
}
